home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / TextToGrid.pprx < prev   
Text File  |  1993-05-25  |  6KB  |  170 lines

  1. /* This Genie fits text to the Y spacing of the grid. For instance, if your grid Y setting is 1.2 picas, all the text in an article will be spaced with lines 14 points apart. This is useful for tidying up parallel columns. You need only click on one box in each article: all the text in a box or linked chain will be changed.
  2. If the grid spacing is large, you may get two or three lines of text in each grid unit.
  3. In this version the bounding boxes of the letters are fitted to the grid; in a later version it may be possible to place the baselines on the grid.
  4. Written by Don Cox  Aug 92   Copyright. Not Public Domain. All rights resrved. */
  5.  
  6. trace n
  7. signal on error
  8. signal on syntax
  9. address command
  10. call SafeEndEdit.rexx()
  11. call ppm_AutoUpdate(0)
  12. cr="0a"x
  13.  
  14. cpage = ppm_CurrentPage()
  15. counter=0
  16.  
  17. do forever
  18.     box=ppm_ClickOnBox("  Click on boxes containing text to be respaced")
  19.     if box=0 then break
  20.     counter=counter+1
  21.     boxes.counter=box
  22.     call ppm_SelectBox(box)
  23. end
  24.  
  25. if counter=0 then exit_msg("No boxes selected")
  26. currentunits=ppm_GetUnits()
  27. call ppm_SetUnits(2)
  28. randval = (randu() * time(s)) % 1 /* mark boxes with random number to avoid doing them twice */
  29.  
  30. gridsize = ppm_GetGridSize()
  31. spacing = word(gridsize,2) /* we only want the Y value */
  32.  
  33.  
  34. call ppm_ShowStatus("  Respacing text...")
  35. do i=1 to counter
  36.     box=boxes.i
  37.  
  38.     boxtype = upper(word(ppm_GetBoxInfo(box), 1))
  39.     if boxtype~="TEXT" then iterate
  40.     oldbox = box
  41.     box = ppm_ArtFirstBox(box)
  42.     boxone = box
  43.     do forever  /* Tops of boxes to grid */
  44.         Ypos = word(ppm_GetBoxPosition(box),2)
  45.         Xpos = word(ppm_GetBoxPosition(box),1)
  46.         oddbit = Ypos//spacing
  47.         if oddbit<= spacing/2 then call ppm_SetBoxPosition(box,Xpos, Ypos-oddbit)
  48.         else call ppm_SetBoxPosition(box,Xpos, Ypos+spacing-oddbit)
  49.         box = ArtNextBox(box)
  50.         if box = 0 then break
  51.         end
  52.     box = boxone
  53.     text = ppm_GetArticleText(box,1)
  54.     text = RespaceText(text,spacing)
  55.     gone = ppm_DeleteContents(box)
  56.     overflow = ppm_TextIntoBox(box,text)
  57.     do while box ~= 0  /* mark all the other boxes in this chain  */
  58.         call ppm_SetBoxUserData(box, randval)
  59.         box = ppm_ArtNextBox(box)
  60.         end
  61.     box = oldbox  /* back to the box we are working on */
  62.     end
  63.  
  64. newpage = ppm_GoToPage(cpage)
  65. call ppm_SetUnits(currentunits)
  66.  
  67. call exit_msg()
  68. end
  69.  
  70. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  71.  
  72. RespaceText: procedure
  73. parse arg text, spacing
  74. position = 1
  75. position2 = 1
  76.  
  77. do forever  /* we have to open up style tags to get sizes */
  78.     position = pos("\dS<",text,position2)
  79.     if position = 0 then break
  80.     position2 = pos(">",text,position)
  81.     if position2 = 0 then break
  82.     styletag = substr(text,position+4, position2-position-4)
  83.     styledef = ppm_GetStyleTagData(styletag)
  84.     styledef = left(styledef,pos("}",styledef)-1) /* remove name of tag */
  85.     styledef = substr(styledef,pos("{",styledef)+1)
  86.     text = delstr(text,position, (position2-position+1)) /* delete tag name */
  87.     text = insert("\ds"styledef,text,(position-1))
  88.     end
  89.  
  90. position2 = 1
  91. do forever  /* first, for relative spacing we need font sizes */
  92.     position = pos("\fs<",text,position2)+4
  93.     if position = 4 then break  /* would be 0 but we added 4 */
  94.     position2 = pos(">",text,position)
  95.     if position2 = 0 then break
  96.     fontsize = substr(text,position, position2-position)
  97.     fontsize = fontsize/28.346457 /* convert to cm  */
  98.     position = pos("\lr<",text,position2)+4
  99.     if position = 4 then break  /* would be 0 but we added 4 */
  100.     position2 = pos(">",text,position)
  101.     if position2 = 0 then break
  102.     relspace = substr(text,position, position2-position)
  103.     text = delstr(text,position, position2-position) /* delete old size */
  104.     newspace = spacing%((relspace/100)*fontsize)
  105.     if newspace = 0 then newspace = 1
  106.     newspace = spacing/newspace*28.346457  /* back to points */
  107.     text = overlay("lf",text,position-3)
  108.     text = insert(newspace,text,position-1)
  109.     end
  110.  
  111.  
  112. position2 = 1
  113. do forever  /*  now fixed line spacings  */
  114.     position = pos("\lf<",text,position2)+4
  115.     if position = 4 then break  /* would be 0 but we added 4 */
  116.     position2 = pos(">",text,position)
  117.     if position2 = 0 then break
  118.     oldsize = substr(text,position, position2-position)
  119.     text = delstr(text,position, position2-position) /* delete old size */
  120.     oldsize = oldsize/28.346457
  121.     newspace = (spacing%oldsize)
  122.     if newspace = 0 then newspace = 1
  123.     newspace = spacing/newspace*28.346457
  124.     text = insert(newspace,text,position-1)
  125.     end
  126.  
  127. position2 = 1
  128. do forever   /* and fixed leading  */
  129.     position = pos("\fs<",text,position2)+4
  130.     if position = 4 then break  /* would be 0 but we added 4 */
  131.     position2 = pos(">",text,position)
  132.     if position2 = 0 then break
  133.     fontsize = substr(text,position, position2-position)
  134.     position = pos("\ll<",text,position2)+4
  135.     if position = 4 then break  /* would be 0 but we added 4 */
  136.     position2 = pos(">",text,position)
  137.     if position2 = 0 then break
  138.     leading = substr(text,position, position2-position)
  139.     text = delstr(text,position, position2-position) /* delete old size */
  140.     newspace = (leading+fontsize)/28.346457
  141.     newspace = (spacing%newspace)
  142.     if newspace = 0 then newspace = 1
  143.     newspace = spacing/newspace*28.346457
  144.     text = overlay("lf",text,position-3)
  145.     text = insert(newspace,text,position-1)
  146.     end
  147.  
  148.  
  149. return text
  150.  
  151.  
  152. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  153.  
  154. error:
  155. syntax:
  156.     do
  157.     exit_msg("Genie failed due to error: "errortext(rc))
  158.     end
  159.  
  160. exit_msg:
  161.     do
  162.     parse arg message
  163.     if message ~= "" then
  164.     call ppm_Inform(1,message,"Resume")
  165.     call ppm_ClearStatus()
  166.     call ppm_AutoUpdate(1)
  167.     exit
  168.     end
  169.  
  170.